package com.sl.au.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.sl.au.entity.ExdeDutyArea;
import com.sl.au.entity.SaleArea;
import com.sl.au.entity.User;

/**
 * 
 * @author yry
 * 2017-03-06 内勤-片区配置DAO
 *
 */
public interface ExdeInsideConfigurationRepository extends JpaRepository<ExdeDutyArea, String> {
	
	/**
	 * 获取所有人员
	 * 
	 * @param superior
	 *            部门
	 * @return
	 */
	@Query("select u from User u where u.saleArea.superior like '%'+?1+'%' ")
	List<User> getAllUserList(String superior);
	
	/**
	 * 获取所有片区
	 * 
	 * @param superior
	 *            部门
	 * @return
	 */
	@Query("select s from SaleArea s where s.superior like '%'+?1+'%' ")
	List<SaleArea> getAllSaleAreaList(String superior);
	
	/**
	 * 获取所有内勤-片区配置
	 * 
	 * @param superior
	 *            部门
	 * @return
	 */
	@Query("select e from ExdeDutyArea e where e.superior like '%'+?1+'%' ")
	List<ExdeDutyArea> getAllExdeDutyAreaList(String superior);
	
	/**
	 * 查询所有内勤-片区配置
	 * 
	 * @param superior
	 *            部门
	 * @return
	 */
	@Query("select e from ExdeDutyArea e where e.superior like '%'+?2+'%' and (e.areaName like '%'+?1+'%' or e.dutyPersonName like '%'+?1+'%' or e.type like '%'+?1+'%') ")
	List<ExdeDutyArea> getExdeDutyAreaList(String key, String superior);
	
	/***
	 * 通过ID删除内勤-片区配置
	 * @param id
	 */
	@Transactional
	@Modifying
	@Query("delete from ExdeDutyArea c where c.id=?")
	void deleteExdeDutyAreaById(String id);
	

}
